﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Linq;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

/// <summary>
/// Summary description for CartItem
/// </summary>
public class CartItem
{
    private int _productID;
    private int _quantity;
    private string name;
    private float price;
    private double cost;

    public double Cost
    {
        get { return Quantity * Price; }
    }
    public string Name
    {
        get { return name; }
        set { name = value; }
    }
    public float Price
    {
        get { return price; }
        set { price = value; }
    }
    public int ProductID
    {
        get { return _productID; }
        set { _productID = value; }

    }

    public int Quantity
    {
        get { return _quantity; }
        set { _quantity = value; }
    }

	public CartItem(int productID, int quantity)
	{
        _productID = productID;
        _quantity = quantity;
        name = GetName(this.ProductID);
        price = GetPrice(this.ProductID);
	}
    public string GetName(int id)
    {
        ChoDienTuDataContext cdt = new ChoDienTuDataContext();
        var kq = cdt.Select_ProductByID(id).First();
        String name = kq.ProductName;
        return name;
    }
    public float GetPrice(int id)
    {
        ChoDienTuDataContext cdt = new ChoDienTuDataContext();
        var kq = cdt.Select_ProductByID(id).First();
        float price = (float)kq.Price;
        return price;
    }
}
